const express=require('express');
const admin=express.Router();
const conservator = require("./admin/conservator");
const axios = require('axios')
const jwt = require("jsonwebtoken")//解析token
admin.get('/',(req, res)=>{
    axios({
        url: 'consumer/showAll',
        method: 'GET',
    })
    .then(data => {
        if(data.data.code==20000){
            
            res.render('admin/index',{userInfo: jwt.decode(req.session.token),showInfo:data.data.data});
        }
    })
    .catch(err => {
        console.log(err.config);
    })
    console.log(req.session.token);
   
});   
admin.get('/loginOut',(req,res)=>{
    req.session.token=null;
    console.log(req.session.token);
    res.redirect('/home/login');
})
const users = require("./admin/users");
const trade = require("./admin/trade");
const store = require("./admin/store");
const index = require("./admin/index");
const goods = require("./admin/goods");
// const fileRouter = require("./admin/fileRouter");
const system = require("./admin/system");
admin.use('/index',index)
admin.use('/conservator',conservator)
admin.use('/users',users)
admin.use('/trade',trade)
admin.use('/store',store)
admin.use('/goods',goods)
// admin.use('/file',fileRouter)
admin.use('/system',system)


// admin.get('/text',(req, res) =>{
//     let {goodsId} = req.query
//     axios({
//         url: 'http://www.mianded.top/inGoodsPage',
//         method: 'POST',
//         params: {
//           goodsId:goodsId,
//         }
//     })
//     .then(data => {
//         console.log("------");
//         console.log(data);
//         res.send(data.data)
//     })
//     .catch(err => {
//         console.log("++++++++");
//         console.log(err.config);
//     })
// })
admin.get('/error',(req,res)=>{
    console.log(req.session.error);
    res.render('admin/error',{
        msg:req.session.error.msg,
        err:req.session.error.status
    })
})
module.exports=admin;



